package com.hc.session.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @Author: huangcheng
 * @CreateTime: 2023-09-15  11:08
 * @Description:
 * @Version: 1.0
 */
@Configuration
public class HttpSessionConfig {

    /*
     * cookie序列化
     */
    @Bean
    public CookieSerializer cookieSerializer() {
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
        //放大作用域，将session信息保存宝test.com中，子域名就可以访问
        cookieSerializer.setDomainName("test.com");
        cookieSerializer.setCookieName("TESTSESSION");
        return cookieSerializer;
    }
    /*
     * redis序列化
     */
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
        return new GenericJackson2JsonRedisSerializer();
    }
}
